import { GTextFormat } from "../../../common/GTextFormat";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { EToplistType } from "../../../../Message/Public/EToplistType";
import { OverlordRankItem } from "./OverlordRankItem";
import { TToplist } from "../../../../Message/Db/Tables/TToplist";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
type int = number;
//class OverlordSprite
    
    export  class OverlordSprite /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._itemArr = [];
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.headTf = new GTextFormat("", 12, 16777113, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this.floorTxt = this.createTxt(16, 0, 60, 30, Language.getString(32087));
            this.namesTxt = this.createTxt(76, 0, 264, 30, Language.getString(32088));
            this.timeTxt = this.createTxt(340, 0, 90, 30, Language.getString(32089));
            var loc1=ObjCreate.createBg(0, 23, 460, 2, this, ImagesConst.SplitLine);
            this.createItem();
            return;
        }

        /* internal  */createTxt(arg1: int, arg2: int, arg3: int, arg4: int, arg5: string): Object /* flash.text.TextField */
        {
            var loc1=null;
            (loc1 = new Object /* flash.text.TextField */()).x = arg1;
            loc1.y = arg2;
            loc1.width = arg3;
            loc1.height = arg4;
            loc1.defaultTextFormat = this.headTf;
            loc1.text = arg5;
            loc1.selectable = false;
            addChild(loc1);
            return loc1;
        }

        public resetTextPos(arg1: int): void
        {
            var loc1=arg1;
            switch (loc1) 
            {
                case EToplistType._EToplistTypeCopyMagicTower: case EToplistType._ETopListTypeCopyTowerSixty:
                {
                    this.floorTxt.text = Language.getString(32087);
                    this.namesTxt.text = Language.getString(32088);
                    this.timeTxt.text = Language.getString(32089);
                    break;
                }
                case EToplistType._EToplistTypeGuildDefence:
                {
                    this.floorTxt.text = Language.getString(32112);
                    this.namesTxt.text = Language.getString(32113);
                    this.timeTxt.text = Language.getString(32114);
                    break;
                }
            }
            return;
        }

        /* internal  */createItem(): void
        {
            var loc3=null;
            var loc1=0;
            var loc2=30;
            var loc4=0;
            while (loc4 < 10) 
            {
                loc3 = new OverlordRankItem();
                loc3.x = loc1;
                loc3.y = loc2;
                loc2 = loc2 + loc3.height;
                loc3.doubleClickEnabled = true;
                this._itemArr.push(loc3);
                loc3.addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickItemHandler);
                loc3.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onMouseDoubleClickHandler);
                addChild(loc3);
                ++loc4;
            }
            return;
        }

        public get curTopList(): TToplist
        {
            return this._curTopList;
        }

        /* internal  */onMouseClickItemHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < 10) 
            {
                loc1 = this._itemArr[loc2] as OverlordRankItem;
                if (loc1.isDraw) 
                {
                    loc1.clearBgColor();
                }
                ++loc2;
            }
            loc1 = arg1.target as OverlordRankItem;
            if (this._curTopList && !(loc1.playerId == this._curTopList.entityId) && !(loc1.type == EToplistType._EToplistTypeGuildDefence)) 
            {
                loc1.onItemLookupPlayerClick(arg1);
            }
            else if (this._curTopList) 
            {
                loc1.drawGrayColor();
            }
            this._curTopList = loc1.data;
            return;
        }

        /* internal  */onMouseDoubleClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as OverlordRankItem;
            loc1.onItemDoubleClickShowPlayerMenu();
            return;
        }

        public setData(arg1: Array<any>, arg2: Boolean, arg3: int): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < 10) 
            {
                (loc1 = this._itemArr[loc2] as OverlordRankItem).updateItem(arg1[loc2], arg3);
                if (loc1.isDraw) 
                {
                    loc1.clearBgColor();
                }
                ++loc2;
            }
            if (this._itemArr && this._itemArr.length > 0) 
            {
                if (!arg2) 
                {
                    this._curTopList = null;
                    return;
                }
                if ((loc1 = this._itemArr[0] as OverlordRankItem).sEntityId != null) 
                {
                    loc1.drawGrayColor();
                    this._curTopList = loc1.data;
                    if (loc1.type != EToplistType._EToplistTypeGuildDefence) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.LookUpTargetEquip, loc1.sEntityId));
                    }
                }
            }
            return;
        }

        public showTargetPlayer(arg1: int): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < 10) 
            {
                loc1 = this._itemArr[loc2] as OverlordRankItem;
                if (loc1.isDraw) 
                {
                    loc1.clearBgColor();
                }
                if (loc1.rank == arg1) 
                {
                    loc1.drawGrayColor();
                    if (loc1.type != EToplistType._EToplistTypeGuildDefence) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.LookUpTargetEquip, loc1.sEntityId));
                    }
                }
                ++loc2;
            }
            return;
        }

        public setItemOnlineState(arg1: int, arg2: int): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < 10) 
            {
                loc1 = this._itemArr[loc2];
                if (loc1.data == null) 
                {
                    return;
                }
                if (loc1.playerId == arg1) 
                {
                    loc1.registerPlayerMenu(arg2);
                    return;
                }
                ++loc2;
            }
            return;
        }

        protected /* var */headTf: Object /* flash.text.TextFormat */;

        protected /* var */floorTxt: Object /* flash.text.TextField */;

        protected /* var */namesTxt: Object /* flash.text.TextField */;

        protected /* var */timeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_itemArr: Array<any>;

        /* internal */ /* var */_curTopList: TToplist;
    }
